package com.teyao.teyao_back.service.impl;


import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.teyao.teyao_back.entity.Product;

import com.teyao.teyao_back.entity.ResponseMessage;
import com.teyao.teyao_back.mapper.ProductMapper;
import com.teyao.teyao_back.service.ProductService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements ProductService {

    //更新库存//入库
    @Override
    public ResponseMessage updateSto(Product product) {
        ResponseMessage responseMessage = new ResponseMessage();
        boolean success = false;
        if (product.getStockCount() >= 0) {
            UpdateWrapper<Product> updateWrapper = new UpdateWrapper<>();
            updateWrapper.eq("product_id", product.getProductId());
            success = baseMapper.update(product, updateWrapper) > 0 ? true : false;
            responseMessage.setSuccess(success);
        }
        return responseMessage;
    }

    @Override
    public List<Product> all() {
        return baseMapper.selectList(null);
    }


}
